package com.tms.springboot.controller;


import com.tms.springboot.base.pojo.PdFleet;
import com.tms.springboot.result.JsonResult;
import com.tms.springboot.result.ResultTool;
import com.tms.springboot.service.PdFleetService;
import com.tms.springboot.utils.UUId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 车队表 前端控制器
 * </p>
 *
 * @author cjj
 * @since 2023-06-14
 */
@RestController
@RequestMapping("/pd-fleet")
public class PdFleetController {

    @Autowired
    private PdFleetService pdFleetService;

    @RequestMapping("/selectPdFleet")
    public List<PdFleet> selectPdFleet(){

        List<PdFleet> list = this.pdFleetService.list();

        return list;

    }

    /**
     * 添加车队
     * @param pdFleet
     * @return
     */
    @RequestMapping("/addFleet")
    public JsonResult addFleet(@RequestBody PdFleet pdFleet) {
        pdFleet.setId(UUId.nextId());
        return this.pdFleetService.save(pdFleet) ? ResultTool.success(): ResultTool.fail();
    }

    /**
     * 修改车队
     * @param pdFleet
     * @return
     */
    @RequestMapping("/updateFleet")
    public JsonResult updateFleet(@RequestBody PdFleet  pdFleet){
        return this.pdFleetService.updateById(pdFleet)? ResultTool.success():ResultTool.fail();
    }

    /**
     * 删除车队
     * @param pdFleet
     * @return
     */

    @RequestMapping("/deleteFleet")
    public JsonResult deleteFleet(@RequestBody PdFleet pdFleet){
        return this.pdFleetService.removeById(pdFleet)? ResultTool.success():ResultTool.fail();
    }
}
